﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lenovo.CFI.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;

namespace Lenovo.CFI.DAL
{
    public class IdeaTypeDa
    {
        public static void InsertIdeaType(int ideaID, string typeCode)
        {
            InsertIdeaType(ideaID, typeCode, DBHelper.GetDatabase(), null);
        }
        public static void InsertIdeaType(int ideaID, string typeCode, TranscationHelper trans)
        {
            InsertIdeaType(ideaID, typeCode, trans.DataBase, trans.Transaction);
        }
        private static void InsertIdeaType(int ideaID, string typeCode, Database db, DbTransaction trans)
        {
            DbCommand dbCommand = db.GetStoredProcCommand("Usp_InsertIdeaType", ideaID, typeCode);

            try
            {
                if (trans == null)
                    db.ExecuteNonQuery(dbCommand);
                else
                    db.ExecuteNonQuery(dbCommand, trans);
            }
            catch (System.Data.SqlClient.SqlException sex)      // 只捕获SqlException，其余抛出继续传播
            {
                DBHelper.ParseSqlException(sex, false);
            }
        }


        public static void DeleteIdeaTypeList(int ideaID)
        {
            DeleteIdeaTypeList(ideaID, DBHelper.GetDatabase(), null);
        }
        public static void DeleteIdeaTypeList(int ideaID, TranscationHelper trans)
        {
            DeleteIdeaTypeList(ideaID, trans.DataBase, trans.Transaction);
        }
        public static void DeleteIdeaTypeList(int ideaID, Database db, DbTransaction trans)
        {
            DbCommand dbCommand = db.GetStoredProcCommand("Usp_DeleteIdeaTypeList", ideaID);

            try
            {
                if (trans == null)
                    db.ExecuteNonQuery(dbCommand);
                else
                    db.ExecuteNonQuery(dbCommand, trans);
            }
            catch (System.Data.SqlClient.SqlException sex)      // 只捕获SqlException，其余抛出继续传播
            {
                DBHelper.ParseSqlException(sex, true);
            }
        }
    }
}
